/* REXX _twgs_reporter.zrx by the reverend (build 66) */ /*- built by rev-builder version 1.1 on 13 Nov 2002 at 16:54:56 -*/ /*- ------------------------------------------------------------------------ -*/ /*- Copyright (C) 2001 Ron Wilson -*/ /*- -*/ /*- This script is free, and can be modified for your personal use, but you -*/ /*- cannot copy or distribute this script or any derivative work based upon -*/ /*- this script without the express permission of the author. Your use of -*/ /*- this script is governed by the terms of the REV-LICENSE. -*/ /*- -*/ /*- This program is provided to you WITHOUT ANY WARRANTY, even the implied -*/ /*- warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -*/ /*- REV-LICENSE for more details. -*/ /*- -*/ /*- A copy of the REV-LICENSE is available at: -*/ /*- http://thereverend.coastgames.com/tradewars/rev-license.html -*/ /*- ------------------------------------------------------------------------ -*/ /* description: this script will monitor players online list from the main */ /* twgs menu. it can do this at regular intervals, convert the */ /* information to html, and send the html to your webserver by */ /* ftp. */ /* rev. 0 - initial release */ /* rev. 1 - ansi converter upgrade */ /* rev. 2 - added refresh interval to the header */ /* rev. 3 - ansi converter bug fix */ call zoctimeout 60 call zocsynctime 1500 call on halt name _halt call zockeyboard "LOCK" if \_pcheck("Selection (? for menu):") then call _error "please start at the twgs prompt." /* GET LOG INFO */ parse value _getloginfo() with lpath ";" ldefault parse value zocgetoption("VTStripSeq") with . '="' emulation '"' parse value zocgetglobaloption("ScriptPath") with . '="' spath '"' /* LOAD USER SETTINGS */ iname=zocgetfilename("choose config file:",spath||"\*.ini") if iname="##CANCEL##" then exit call _newline _ansi("bt;fgr") parse value _getgameinfo(iname) with spath ";" iname ";" game htmltitle=_ini_askstr("html title?", "untitled", iname, game, "htmltitle") htmlpath=_ini_askstr("where do put the html?", "c:\", iname, game, "localpath") if htmlpath="" then exit prefix=_ini_askstr("what file prefix?", "gameA", iname, game, "prefix") if prefix="" then exit interval=_ini_askint("how often to refresh (minutes)?", 60, iname, game, "interval") if interval=0 then exit if interval<2 then interval=2 address=_ini_askstr("address?", "", iname, "*ftp", "address") username=_ini_askstr("username?", "", iname, "*ftp", "username") password=_ini_askstr("password?", "", iname, "*ftp", "password") remotewd=_ini_askstr("remote working directory?", "", iname, "*ftp", "remotewd") mode=_ini_askstr("transfer mode?", "ascii", iname, "*ftp", "mode") wmode=_chooselisti("ftp window?","normal;hidden;minimized;no ftp", ";", "c")-1 /* DEFINE HEADER */ infile=prefix||"_log.ans" hdr1="REV-SCRIPT - _twgs_reporter.zrx r.3 - " startover: /* START LOGGING TO INFILE */ if _fileexists(lpath||infile) then call dosdel lpath||infile call zocsetoption('VTStripSeq=no') call zoclogging 0, 1 call zoclogname infile call zoclogging 1, 1 /* WRITE HEADER TO LOG */ call zocwriteln _ansi("bt;frd")||hdr1||date("N")||", "||time("N")||", refresh every "||interval||" minutes."||_ansi("bt;fwh") call zocwriteln /* WRITE Players Online TO LOG */ call zocsend "#" if zocwait("Players Online")=640 then call _error "timeout" if zocwait("Selection (? for menu):")=640 then call _error "timeout" /* STOP LOGGING TO INFILE */ call zoclogging 0, 1 call zoclogname ldefault call zoclogging 1, 1 call zocsetoption('VTStripSeq='||emulation) /* CONVERT LOG ANSI TO HTML */ outfile=prefix||".html" call _ansi_to_html lpath||infile, htmlpath||outfile, "REV-SCRIPT - "||htmltitle /* FTP TO WEBSERVER */ if wmode<3 then do call zocwrite "ftp in progress ... " if _ftp(address, username, password, , remotewd, mode, htmlpath, outfile, wmode) then call zocwriteln "SUCCESS!" else call zocwriteln "FAILED!" end /*if*/ /* WAIT FOR NEXT INTERVAL */ now=time("S")/60 stop=(now%interval)*interval+interval if (stop-now)<2 then stop=stop+interval done=0 do while \done if now>=stop | (stop-now)>=1440 then done=1 else do delay=min(10,trunc(((stop-now)//1440)*60)) hh=trunc(((stop-now)//1440)/60) if hh<10 then hh="0"||hh mm=trunc(((stop-now)//1440)-hh*60) if mm<10 then mm="0"||mm ss=trunc((((stop-now)//1440)//1)*60) if ss<10 then ss="0"||ss call zocwrite _ansi("bt;fgr")||"< refresh in "||hh||":"||mm||":"||ss||" > "||_ansi("bt;fwh") call zocdelay delay call zocsend "#" if zocwait("Players Online")=640 then call _error "timeout" if zocwait("Selection (? for menu):")=640 then call _error "timeout" now=time("S")/60 end /*else*/ end /*do*/ signal startover exit _halt: procedure call zocwriteln "^M^J^[[1;33m<< script aborted by user. >>^[[0m " exit return _error: procedure msg="<< script error: "||arg(1)||" >>" mail="<< if this is a serious problem, email me at: the.reverend@coastgames.com >> " call zocwriteln call zocwriteln "^[[1;31m"||msg||"^[[0m" if arg(1)\="timeout" then call zocwriteln "^[[1;33m"||mail||"^[[0m" call _beep "error.wav" exit return /*** THE REVEREND'S TW LIBRARY FOR ZOC/REXX ***/ /** _pcheck v.4 **/ _pcheck: procedure expose (globals) pc1=arg(1) pc2=zocgetscreen(0, zocgetinfo("CURSOR-Y"), zocgetinfo("CURSOR-X")) rslt=0 do i=1 to _dwords(pc1,";") if _instr(_dword(pc1,i,";"),pc2,"cs") then rslt=1 end /*do*/ return rslt /** _getloginfo v.2 **/ _getloginfo: procedure expose (globals) parse value zocgetoption("CaptDefaultName") with . '="' ldefault '"' parse value zocgetglobaloption("CapturePath") with . '="' lpath '"' lpath=dosfname(lpath) if right(lpath,1)\="\" then lpath=lpath||"\" if \dosisdir(lpath) then call _error "invalid path in _getloginfo" rslt=lpath||";"||ldefault return rslt /** _newline v.2 **/ _newline: procedure expose (globals) if zocgetinfo("CURSOR-X")>0 then call zocwriteln arg(1) else call zocwrite arg(1) return /** _ansi v.3 **/ _ansi: procedure expose (globals) rslt="0" do i=1 to _dwords(arg(1),";") w=_dword(arg(1),i,";") select when w="dl" then rslt=rslt||";"||0 /* dull */ when w="bt" then rslt=rslt||";"||1 /* bright */ when w="ul" then rslt=rslt||";"||4 /* underlined */ when w="blk" then rslt=rslt||";"||5 /* blinking */ when w="fbk" then rslt=rslt||";"||30 /* black foreground */ when w="frd" then rslt=rslt||";"||31 /* red foreground */ when w="fgr" then rslt=rslt||";"||32 /* green foreground */ when w="fye" then rslt=rslt||";"||33 /* yellow foreground */ when w="fbl" then rslt=rslt||";"||34 /* blue foreground */ when w="fmg" then rslt=rslt||";"||35 /* magenta foreground */ when w="fcy" then rslt=rslt||";"||36 /* cyan foreground */ when w="fwh" then rslt=rslt||";"||37 /* white foreground */ when w="bbk" then rslt=rslt||";"||40 /* black background */ when w="brd" then rslt=rslt||";"||41 /* red background */ when w="bgr" then rslt=rslt||";"||42 /* green background */ when w="bye" then rslt=rslt||";"||43 /* yellow background */ when w="bbl" then rslt=rslt||";"||44 /* blue background */ when w="bmg" then rslt=rslt||";"||45 /* magenta background */ when w="bcy" then rslt=rslt||";"||46 /* cyan background */ when w="bwh" then rslt=rslt||";"||47 /* white background */ otherwise nop end /*select*/ end /*do*/ rslt="^[["||rslt||"m" return rslt /** _getgameinfo v.5 **/ _getgameinfo: procedure expose (globals) spath=_getscriptpath() base=spath||"script.ini" if arg(1,"E") then fname=arg(1) else fname=base parse value zocgetglobaloption("WindowTitle") with . '="' game '"' if fname\=base | game="" | game="%ZOCORHOST% %OPTIONS%" then do list=_ini_getheadings(fname) if list="##EOF##" then game="##EOF##" else do templist="" do i=1 to _dwords(list,";") temp=_dword(list,i,";") if left(temp,1)\="*" then do if templist="" then templist=temp else templist=templist||";"||temp end /*if*/ end /*do*/ list=templist game=_drequestlist("select a game:", list, ";", "c") end /*else*/ end /*do*/ call zocwrite _ansi("bt;fgr")||"< using " if length(fname)>17 then call zocwrite "..." call zocwriteln right(fname,min(length(fname),17))||" - ["||game||"] >" rslt=spath||";"||fname||";"||game return rslt /** _ini_askstr v.5 **/ _ini_askstr: procedure expose (globals) if \arg(1,"E") then msg="enter a number" else msg=arg(1) do i=2 to 5 if \arg(i,"E") then call _error "missing parameter in _ini_askstr" end /*do*/ default=arg(2) fname=arg(3) section=arg(4) key=arg(5) mode=lower(arg(6)) if section="##EOF##" then rslt="##EOF##" else rslt=_ini_read(fname, section, key) select when rslt="##EOF##" & msg="##DEFAULT##" then rslt=default when rslt="##EOF##" then rslt=_askstr(msg||" ("||key||"=)",default,"c") when mode="quiet" then nop when mode="" then do call zocwrite _ansi("bt;fgr")||"< using " if length(fname)>17 then call zocwrite "..." call zocwrite right(fname,min(length(fname),17))||" - " call zocwrite key||"="||left(translate(rslt,"~","^"),min(length(rslt),25)) if length(rslt)>25 then call zocwrite "..." call zocwriteln " >" end /*when*/ otherwise nop end /*select*/ return rslt /** _ini_askint v.5 **/ _ini_askint: procedure expose (globals) if \arg(1,"E") then msg="enter an integer" else msg=arg(1) do i=2 to 5 if \arg(i,"E") then call _error "missing parameter in _ini_askint" end /*do*/ default=arg(2) fname=arg(3) section=arg(4) key=arg(5) mode=lower(arg(6)) if _stripint(default)\=default then call _error "invalid parameter in _ini_askint" if section="##EOF##" then rslt="##EOF##" else rslt=_ini_read(fname, section, key) select when rslt="##EOF##" & msg="##DEFAULT##" then rslt=_stripint(default) when rslt="##EOF##" then rslt=_askint(msg||" ("||key||"=)",default,"c") when mode="quiet" then rslt=_stripint(rslt) when mode="" then do call zocwrite _ansi("bt;fgr")||"< using " if length(fname)>17 then call zocwrite "..." call zocwriteln right(fname,min(length(fname),17))||" - "||key||"="||rslt||" >" rslt=_stripint(rslt) end /*when*/ otherwise nop end /*select*/ return rslt /** _chooselisti v.2 **/ _chooselisti: procedure expose (globals) prompt=arg(1) list=arg(2) if list="" then call _error "no list" delim=arg(3) if delim="" then delim=" " if length(delim)>1 then call _error "long delimiter" ch.="" i=_dwords(list,delim) do j=1 to i ch.j=_dword(list,j,delim) end /*do*/ if i<7 then max=1 if i<5 then max=0 if i>=7 then max=(i-5)%2+1 done=0 pos=0 do while \done if pos<0 then pos=0 if pos>max then pos=max select when pos=0 then do if max=0 then ans=zocrequest(prompt, ch.1, ch.2, ch.3, ch.4) else ans=zocrequest(prompt, ch.1, ch.2, ch.3, "next") end /*when*/ when pos=max then do p1=(pos-1)*2+4 p2=p1+1 p3=p1+2 ans=zocrequest(prompt, "back", ch.p1, ch.p2, ch.p3) end /*when*/ otherwise do p1=(pos-1)*2+4 p2=p1+1 ans=zocrequest(prompt, "back", ch.p1, ch.p2, "next") end /*otherwise*/ end /*select*/ select when ans="next" then pos=pos+1 when ans="back" then pos=pos-1 when ans="##CANCEL##" then done=1 when ans="" then nop otherwise done=1 end /*select*/ end /*do*/ rslt=0 do j=1 to i if ans=ch.j then do rslt=j leave end /*if*/ end /*do*/ if lower(arg(4))="c" & ans="##CANCEL##" then call _quit "script cancelled by user.", "nocopy" return rslt /** _fileexists v.3 **/ _fileexists: procedure expose (globals) if \arg(1,"E") then call _error "missing parameter in _fileexists" if stream(arg(1), "C", "QUERY EXISTS")="" then rslt=0; else rslt=1 return rslt /** _ansi_to_html v.4 **/ _ansi_to_html: procedure expose (globals) do i=1 to 2 if arg(i,"O") | \arg(i,"E") then call _error "missing parameter in _ansi_to_html" end /*do*/ infile=arg(1) outfile=arg(2) if arg(3,"E") then title=arg(3) else title="REV-SCRIPT" success=0 /* define constants */ esc=d2c(27) cr=d2c(13) lf=d2c(10) fface='Terminal' fsize=2 /* define colors */ color.="" color.30='#000000' /* black */ color.31='#6A0000' /* red */ color.32='#006A00' /* green */ color.33='#6A6A00' /* yellow */ color.34='#00006A' /* blue */ color.35='#800080' /* magenta */ color.36='#006A6A' /* cyan */ color.37='#A0A0A0' /* white */ color.130='#A0A0A0' color.131='#D40000' color.132='#00FF00' color.133='#D4D400' color.134='#0000D4' color.135='#D400D4' color.136='#00D4D4' color.137='#FFFFFF' do i=30 to 37 temp=i+10 color.temp=color.i temp=i+110 color.temp=color.i end /*do*/ /* initialize colors */ reset=1 bright=0 /* 1 */ underline=0 /* 4 */ blink=0 /* 5 */ reverse=0 /* 7 */ hidden=0 /* 8 */ bg=30 fg=37 /* initialize counters */ incode=0 count=0 ignore=0 lastspace=1 html="" if _fileopenr(infile) then do if _filenew(outfile,"delete") then do call _newline call zocwrite _ansi("bt;fwh;bbk")||'writing file: "'||outfile||'" ' mon=_spinner(0,25) call lineout outfile, '